<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<pre>
    后面只能插入大于所有元素的值
    前面只能插入小于所有元素的值
</pre>
<script>
    var List= function () {
        this.data=[10,20,30,'c','k','y'];
    }
    List.prototype={
        constructor:List,

        append: function (elm) {//大于所有元素才插入
            var dType,eType=typeof elm,smaller=false;
            if('number'!==eType && 'string'!==eType)return false;
            for(var i=0;i<this.data.length;i++){
                dType=typeof this.data[i];
                if('number'!==dType && 'string'!==dType)return false;
                if(dType==eType){
                    if(elm<=this.data[i]){
                        smaller=true;
                    }
                }
            }
            if(smaller)return false;
            this.data[this.data.length]=elm;
            return true;
        },

        prepend: function (elm) {//小于所有元素才插入
            var dType,eType=typeof elm,bigger=false;
            if('number'!==eType && 'string'!==eType)return false;
            for(var i=0;i<this.data.length;i++){
                dType=typeof this.data[i];
                if('number'!==dType && 'string'!==dType)return false;
                if(dType==eType){
                    if(elm>=this.data[i]){
                        bigger=true;
                    }
                }
            }
            if(bigger)return false;
            this.data.unshift(elm);
            return true;
        }
    }

    var list=new List();
    console.warn('append:');
    console.log(list.append(10),list);
    console.info(list.append(90),list);

    console.log(list.append('y'),list);

    console.log(list.append('a'),list);
    console.log(list.append('x'),list);
    console.info(list.append('z'),list);

    console.log(list.append(function(){}),list);
    console.log(list.append(function(){}),list);

    console.warn('prepend:');
    console.log(list.prepend(9))
    console.log(list.prepend(10))
    console.log(list.prepend('a'))
    console.log(list.prepend('c'))

</script>
</body>
</html>